﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace 灵溪工具箱
{
    public class ColorLightenConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is SolidColorBrush solidColorBrush && double.TryParse(parameter.ToString(), out double factor))
            {
                Color originalColor = solidColorBrush.Color;
                byte r = (byte)(originalColor.R + (255 - originalColor.R) * factor);
                byte g = (byte)(originalColor.G + (255 - originalColor.G) * factor);
                byte b = (byte)(originalColor.B + (255 - originalColor.B) * factor);
                return new SolidColorBrush(Color.FromRgb(r, g, b));
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class ColorDarkenConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is SolidColorBrush solidColorBrush && double.TryParse(parameter.ToString(), out double factor))
            {
                Color originalColor = solidColorBrush.Color;
                byte r = (byte)(originalColor.R * (1 - factor));
                byte g = (byte)(originalColor.G * (1 - factor));
                byte b = (byte)(originalColor.B * (1 - factor));
                return new SolidColorBrush(Color.FromRgb(r, g, b));
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}